package com.ruoyi.web.controller.life;

import java.util.List;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.life.LifeFamilyFriends;
import com.ruoyi.system.service.life.ILifeFamilyFriendsService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 亲戚朋友Controller
 *
 * @author ruoyi
 * @date 2024-01-22
 */
@RestController
@RequestMapping("/life/friends")
public class LifeFamilyFriendsController extends BaseController {
    @Autowired
    private ILifeFamilyFriendsService lifeFamilyFriendsService;

    /**
     * 查询亲戚朋友列表
     */
    @PreAuthorize("@ss.hasPermi('life:friends:list')")
    @GetMapping("/list")
    public TableDataInfo list(LifeFamilyFriends lifeFamilyFriends) {
        startPage();
        List<LifeFamilyFriends> list = lifeFamilyFriendsService.selectLifeFamilyFriendsList(lifeFamilyFriends);
        return getDataTable(list);
    }

    /**
     * 导出亲戚朋友列表
     */
    @PreAuthorize("@ss.hasPermi('life:friends:export')")
    @Log(title = "亲戚朋友", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LifeFamilyFriends lifeFamilyFriends) {
        List<LifeFamilyFriends> list = lifeFamilyFriendsService.selectLifeFamilyFriendsList(lifeFamilyFriends);
        ExcelUtil<LifeFamilyFriends> util = new ExcelUtil<LifeFamilyFriends>(LifeFamilyFriends.class);
        util.exportExcel(response, list, "亲戚朋友数据");
    }

    /**
     * 获取亲戚朋友详细信息
     */
    @PreAuthorize("@ss.hasPermi('life:friends:query')")
    @GetMapping(value = "/{lUserId}")
    public AjaxResult getInfo(@PathVariable("lUserId") String lUserId) {
        return success(lifeFamilyFriendsService.selectLifeFamilyFriendsByLUserId(lUserId));
    }

    /**
     * 新增亲戚朋友
     */
    @PreAuthorize("@ss.hasPermi('life:friends:add')")
    @Log(title = "亲戚朋友", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LifeFamilyFriends lifeFamilyFriends) {
        return toAjax(lifeFamilyFriendsService.insertLifeFamilyFriends(lifeFamilyFriends));
    }

    /**
     * 修改亲戚朋友
     */
    @PreAuthorize("@ss.hasPermi('life:friends:edit')")
    @Log(title = "亲戚朋友", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LifeFamilyFriends lifeFamilyFriends) {
        return toAjax(lifeFamilyFriendsService.updateLifeFamilyFriends(lifeFamilyFriends));
    }

    /**
     * 删除亲戚朋友
     */
    @PreAuthorize("@ss.hasPermi('life:friends:remove')")
    @Log(title = "亲戚朋友", businessType = BusinessType.DELETE)
    @DeleteMapping("/{lUserIds}")
    public AjaxResult remove(@PathVariable String[] lUserIds) {
        return toAjax(lifeFamilyFriendsService.deleteLifeFamilyFriendsByLUserIds(lUserIds));
    }
}
